package com.g3net.tool;

public class AdressUtil {
	
   public static String[] pro={"河北","山西","吉林","黑龙江","江苏","浙江","安徽","江西","山东","河南","湖北","湖南","广东","四川","贵州","云南","陕西","甘肃","青海","陕西","甘肃"};

	public static String getProvince(String address){
		for (int i = 0; i < pro.length; i++) {
			if (address.indexOf(pro[i])>-1) {
				return pro[i]+"省";
			}
		}
		return null;
	}
	
	public static String getCity(String address){
		int start=address.indexOf("省");
		int end=address.indexOf("市");
		int next=address.indexOf("县");
		int proPosition=getProvincePosition(address);
		if (start!=-1&&end!=-1) {
			return address.substring(start+1,end);
		}else if(start!=-1&&next!=-1){
			return address.substring(start+1,next);
		}else if(proPosition>=0&&end!=-1){
			if (proPosition==0) {
				return address.substring(0,end);
			}else {
				return address.substring(proPosition+1,end);
			}
			
		}
		
		
		return address;
	}
	
	
	public static int getProvincePosition(String address){
		for (int i = 0; i < pro.length; i++) {
			int a=address.indexOf(pro[i]);
			if (address.indexOf(pro[i])>-1) {
				return a;
			}
		}
		return 0;
	}
	
	public static void main(String[] args) {
		String abc =getCity("西宁");
//		String ccc =getProvince("青海省西宁市城中区南川西路164号");
		System.out.println(abc);
	}


}
